﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="UserManagment.aspx.cs"
    Inherits="TestProject.Admin.UserManagment" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:GridView ID="GridView1" runat="server" 
        DataSourceID="ObjectDataSourceAuthors" AllowPaging="True"
        AutoGenerateColumns="False">
        <Columns>
            <asp:CommandField ShowEditButton="true"  />
            <asp:CommandField ShowDeleteButton="true" />

            <asp:TemplateField SortExpression="UserName"   HeaderText="User">
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("UserName") %>' ID="UserName"></asp:Label>
                </ItemTemplate>
                
            </asp:TemplateField>
            <asp:TemplateField SortExpression="RoleName" HeaderText="Role">
                <EditItemTemplate>
                    <asp:DropDownList runat="server" ID="editRoleName" DataSourceID="SqlDataSourceGetRoles"
                        DataValueField="rolename" DataTextField="rolename" SelectedValue='<%# Bind("RoleName") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("RoleName") %>' ID="Label4"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:ObjectDataSource ID="ObjectDataSourceAuthors" runat="server" TypeName="DBUserManagment"
        SelectMethod="GetAllUsers" UpdateMethod="UpdateUser" DeleteMethod="RemoveUser">
        <UpdateParameters>
            <asp:Parameter Name="UserName" Type="String" />
            <asp:Parameter Name="RoleName" Type="String" />
        </UpdateParameters>
        <DeleteParameters>
            <asp:Parameter Name="UserName" Type="String" />
        </DeleteParameters>
    </asp:ObjectDataSource>

        <asp:ObjectDataSource ID="ObjectDataSourceAddAuthor" runat="server" TypeName="DBUserManagment"
        InsertMethod="AddUser" SelectMethod="GetAllUsers">
            <InsertParameters>
                <asp:Parameter Name="username" />
                <asp:Parameter Name="password" />
                <asp:Parameter Name="rolename" />
            </InsertParameters>
        </asp:ObjectDataSource>


    <asp:SqlDataSource ID="SqlDataSourceGetRoles" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT [RoleName] FROM [vw_aspnet_Roles] union Select NULL">
    </asp:SqlDataSource>
    
    <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" 
        DataSourceID="ObjectDataSourceAddAuthor" AutoGenerateRows="False"  OnItemInserted="DetailsView1_ItemInserted">
        <Fields>
            <asp:CommandField HeaderText="Add author" ShowHeader="True" ShowInsertButton="True" />
            <asp:TemplateField HeaderText="Author">
                <InsertItemTemplate>
                    <asp:Label runat="server" Text="Name:"></asp:Label><br />
                    <asp:TextBox runat="server" ID="InsertedName" Text='<%# Bind("username") %>' />
                    <asp:Label runat="server" Text="Password:"></asp:Label><br />
                    <asp:TextBox runat="server" ID="InsertedPassword" Text='<%# Bind("password") %>' />
                    <asp:Label runat="server" Text="Role:"></asp:Label><br />
                    <asp:DropDownList runat="server" ID="TextBox1" DataSourceID="SqlDataSourceGetRoles"
                        DataValueField="rolename" DataTextField="rolename" SelectedValue='<%# Bind("rolename") %>' />
                </InsertItemTemplate>
            </asp:TemplateField>
        </Fields>
    </asp:DetailsView>
</asp:Content>
